<?php

class Application_Model_Base
{
  /* every field in db table , such as:
   * array('id'=>3, 'name'=>'wang', 'age'=>18);
   */
  protected $data = array(); 
  /* name of the primary key, such as 'id' */
  protected $primary_key_name = '';

  public function __construct(array $options = null)
  {
    if (is_array($options)) {
      $this->setOptions($options);
    }
  }
  public function getPrimaryKey()
  {
    return $this->primary_key_name;
  }

  public function set($key, $val)
  {
    if (array_key_exists($key, $this->data))
      $this->data[$key] = $val;
  }

  public function get($key)
  {
    if (array_key_exists($key, $this->data))
      return $this->data[$key];
  }

  public function setOptions(array $options = null)
  {
    if (is_array($options)) {
      foreach ($options as $key => $val) {
	if (array_key_exists($key, $this->data))
	  $this->set($key, $val);
      }
    }
    /* clear the options */
    else
      {
	foreach($this->data as $key => $val)
	  {
	    $this->set($key, '');
	  }
      }
	
    return $this;
  }
  public function getOptions()
  {
    return $this->data;
  }
};
